<template>
  <div class="login-container">
    <form class="form">
      <div class="form-item">
        <div class="label">用户名</div>
        <input type="text" v-model="userForm.userName">
      </div>
      <div class="form-item">
        <div class="label">密码</div>
        <input type="password" v-model="userForm.password">
      </div>
      <div class="form-item">
        <div class="label"></div>
        <button @click="onsubmit">登录</button>
      </div>
      <div class="form-item">
        <div class="label"></div>
        <button @click="toRegister">注册</button>
      </div>
    </form>
  </div>
</template>

<script>
  import { login } from '@/api/user'
  export default {
    name: 'Login',
    data () {
      return {
        userForm: {
          userName: '',
          password: ''
        }
      }
    },
    methods: {
      // 登录
      onsubmit () {
        login(this.userForm)
          .then(res => {
            console.log(res)
            alert('登录成功！')
            this.$router.push({
              name: 'UserList'
            })
          })
      },

      // 去注册
      toRegister() {
        this.$router.push({
          name: 'Register'
        })
      }
    }
  }
</script>

<style scoped lang="scss">
  .login-container {
    .form {
      .form-item {
        margin-top: 10px;
        .label {
          width: 100px;
          display: inline-block;
        }
      }
    }
  }
</style>
